/*     */ package me.wazup.kitbattle;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Random;
/*     */ import org.bukkit.Bukkit;
/*     */ import org.bukkit.Effect;
/*     */ import org.bukkit.Location;
/*     */ import org.bukkit.Material;
/*     */ import org.bukkit.Sound;
/*     */ import org.bukkit.block.Block;
/*     */ import org.bukkit.block.BlockState;
/*     */ import org.bukkit.block.Sign;
/*     */ import org.bukkit.entity.AnimalTamer;
/*     */ import org.bukkit.entity.Arrow;
/*     */ import org.bukkit.entity.Bat;
/*     */ import org.bukkit.entity.Chicken;
/*     */ import org.bukkit.entity.Damageable;
/*     */ import org.bukkit.entity.Entity;
/*     */ import org.bukkit.entity.EntityType;
/*     */ import org.bukkit.entity.Horse;
/*     */ import org.bukkit.entity.IronGolem;
/*     */ import org.bukkit.entity.Player;
/*     */ import org.bukkit.entity.Snowball;
/*     */ import org.bukkit.entity.TNTPrimed;
/*     */ import org.bukkit.entity.Wolf;
/*     */ import org.bukkit.event.EventHandler;
/*     */ import org.bukkit.event.Listener;
/*     */ import org.bukkit.event.block.Action;
/*     */ import org.bukkit.event.entity.EntityDamageByEntityEvent;
/*     */ import org.bukkit.event.entity.EntityDamageEvent;
/*     */ import org.bukkit.event.entity.EntityDeathEvent;
/*     */ import org.bukkit.event.entity.EntityExplodeEvent;
/*     */ import org.bukkit.event.entity.ProjectileLaunchEvent;
/*     */ import org.bukkit.event.player.PlayerFishEvent;
/*     */ import org.bukkit.event.player.PlayerInteractEntityEvent;
/*     */ import org.bukkit.event.player.PlayerInteractEvent;
/*     */ import org.bukkit.inventory.ItemStack;
/*     */ import org.bukkit.metadata.FixedMetadataValue;
/*     */ import org.bukkit.metadata.MetadataValue;
/*     */ import org.bukkit.plugin.Plugin;
/*     */ import org.bukkit.potion.PotionEffect;
/*     */ import org.bukkit.potion.PotionEffectType;
/*     */ import org.bukkit.scheduler.BukkitRunnable;
/*     */ import org.bukkit.util.Vector;
/*     */ 
/*     */ public class AbilityListener
/*     */   implements Listener {
/*     */   private main plugin;
/*  50 */   ArrayList<Entity> toRemove = new ArrayList<Entity>();
/*  51 */   ArrayList<BlockState> toRollback = new ArrayList<BlockState>();
/*     */   
/*     */   String kb;
/*  54 */   Random random = new Random();
/*     */   public AbilityListener(main plugin, String kb) {
/*  56 */     this.plugin = plugin;
/*  57 */     this.kb = kb;
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void AbilityInteractEvent(PlayerInteractEvent e) {
/*  62 */     final Player p = e.getPlayer();
/*  63 */     if (!hasKit(p))
/*  64 */       return;  Material item = p.getItemInHand().getType();
/*  65 */     if (item.equals(Material.FIREWORK)) {
/*  66 */       if (hasAbility(p, Ability.KANGAROO)) {
/*  67 */         e.setCancelled(true);
/*  68 */         if (p.isOnGround()) {
/*  69 */           Vector vector = p.getEyeLocation().getDirection();
/*  70 */           if (p.isSneaking()) {
/*  71 */             vector.setY(0.2D);
/*  72 */             vector.multiply(4);
/*     */           } else {
/*  74 */             vector.setY(1.2D);
/*     */           } 
/*  76 */           p.setVelocity(vector);
/*     */         } 
/*     */       } 
/*     */       
/*     */       return;
/*     */     } 
/*  82 */     if (item.equals(Material.IRON_FENCE)) {
/*  83 */       if (hasAbility(p, Ability.PRISONER)) {
/*  84 */         if (hasCooldown(p)) {
/*  85 */           sendStillOnCooldown(p);
/*     */           return;
/*     */         } 
/*  88 */         sendUseAbility(p);
/*  89 */         setCooldown(p, this.plugin.config.PrisonerCooldown);
/*  90 */         p.throwSnowball().setMetadata("prison", (MetadataValue)new FixedMetadataValue((Plugin)this.plugin, Boolean.valueOf(true)));
/*     */       } 
/*     */       return;
/*     */     } 
/*  94 */     if (item.equals(Material.WEB)) {
/*  95 */       if (hasAbility(p, Ability.SPIDERMAN)) {
/*  96 */         if (hasCooldown(p)) {
/*  97 */           sendStillOnCooldown(p);
/*     */           return;
/*     */         } 
/* 100 */         sendUseAbility(p);
/* 101 */         setCooldown(p, this.plugin.config.SpidermanCooldown);
/* 102 */         p.throwSnowball().setMetadata("spiderman", (MetadataValue)new FixedMetadataValue((Plugin)this.plugin, Boolean.valueOf(true)));
/*     */       } 
/*     */       
/*     */       return;
/*     */     } 
/*     */     
/* 108 */     if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
/* 109 */       if (item.equals(Material.BONE)) {
/* 110 */         if (hasAbility(p, Ability.HADES)) {
/* 111 */           if (hasCooldown(p)) {
/* 112 */             sendStillOnCooldown(p);
/*     */             return;
/*     */           } 
/* 115 */           sendUseAbility(p);
/* 116 */           setCooldown(p, this.plugin.config.HadesCooldown);
/* 117 */           final List<Wolf> wolfs = new ArrayList<Wolf>();
/* 118 */           for (int i = 0; i < this.plugin.config.HadesAmountOfDogs; i++) {
/* 119 */             Wolf wolf = (Wolf)p.getWorld().spawnEntity(p.getLocation(), EntityType.WOLF);
/* 120 */             wolf.setCustomName(String.valueOf(p.getName()) + "'s Wolf");
/* 121 */             wolf.setOwner((AnimalTamer)p);
/* 122 */             wolf.setMaxHealth(20.0D);
/* 123 */             wolf.setHealth(20.0D);
/* 124 */             wolf.setMetadata("toRemove", (MetadataValue)new FixedMetadataValue((Plugin)this.plugin, Boolean.valueOf(true)));
/* 125 */             wolf.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 99999, 2));
/* 126 */             wolfs.add(wolf);
/*     */           } 
/* 128 */           this.toRemove.addAll(wolfs);
/* 129 */           Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, new Runnable() {
/*     */                 public void run() {
/* 131 */                   for (Wolf wolf : wolfs) {
/* 132 */                     wolf.remove();
/*     */                   }
/* 134 */                   AbilityListener.this.toRemove.removeAll(wolfs);
/*     */                 }
/* 136 */               },  this.plugin.config.HadesDogsLastFor);
/*     */         } 
/*     */         return;
/*     */       } 
/* 140 */       if (item.equals(Material.WOOD_AXE)) {
/* 141 */         if (hasAbility(p, Ability.THOR)) {
/* 142 */           if (hasCooldown(p)) {
/* 143 */             sendStillOnCooldown(p);
/*     */             return;
/*     */           } 
/* 146 */           setCooldown(p, this.plugin.config.ThorCooldown);
/* 147 */           sendUseAbility(p);
/* 148 */           for (Entity x : p.getNearbyEntities(this.plugin.config.ThorStrikeRadius, this.plugin.config.ThorStrikeRadius, this.plugin.config.ThorStrikeRadius)) {
/* 149 */             if (!(x instanceof Damageable))
/* 150 */               continue;  if (x instanceof Player && !hasKit((Player)x)) {
/* 151 */               p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.UseAbilityDeny);
/*     */               continue;
/*     */             } 
/* 154 */             p.getWorld().strikeLightningEffect(x.getLocation());
/* 155 */             ((Damageable)x).damage(this.plugin.config.ThorLightningDamage, (Entity)p);
/*     */           } 
/*     */         } 
/*     */         return;
/*     */       } 
/* 160 */       if (item.equals(Material.FIREBALL)) {
/* 161 */         if (hasAbility(p, Ability.DRAGON)) {
/* 162 */           e.setCancelled(true);
/* 163 */           if (hasCooldown(p)) {
/* 164 */             sendStillOnCooldown(p);
/*     */             return;
/*     */           } 
/* 167 */           setCooldown(p, this.plugin.config.DragonCooldown);
/* 168 */           sendUseAbility(p);
/* 169 */           (new BukkitRunnable() {
/* 170 */               int bursts = 0;
/* 171 */               int halfDis = AbilityListener.this.plugin.config.DragonFireRange / 2;
/*     */               public void run() {
/* 173 */                 Location location = p.getTargetBlock(null, this.halfDis).getLocation();
/* 174 */                 p.getWorld().playEffect(location, Effect.MOBSPAWNER_FLAMES, 1);
/* 175 */                 Bat bat = (Bat)p.getWorld().spawnEntity(location, EntityType.BAT);
/* 176 */                 for (Entity e : bat.getNearbyEntities(this.halfDis, this.halfDis, this.halfDis)) {
/* 177 */                   if (!(e instanceof Damageable) || 
/* 178 */                     e.equals(p) || e.equals(bat))
/* 179 */                     continue;  if (e.getType().equals(EntityType.PLAYER) && !AbilityListener.this.hasKit((Player)e)) {
/* 180 */                     p.sendMessage(String.valueOf(AbilityListener.this.kb) + AbilityListener.this.plugin.msgs.UseAbilityDeny);
/*     */                     continue;
/*     */                   } 
/* 183 */                   ((Damageable)e).damage(AbilityListener.this.plugin.config.DragonDamageDealt, (Entity)p);
/* 184 */                   e.setFireTicks(AbilityListener.this.plugin.config.DragonFireLastsFor);
/*     */                 } 
/* 186 */                 bat.remove();
/* 187 */                 this.bursts++;
/* 188 */                 if (this.bursts == AbilityListener.this.plugin.config.DragonAmountOfBursts) {
/* 189 */                   cancel();
/*     */                 }
/*     */               }
/* 192 */             }).runTaskTimer((Plugin)this.plugin, 0L, 20L);
/*     */         } 
/*     */         return;
/*     */       } 
/* 196 */       if (item.equals(Material.REDSTONE_TORCH_ON)) {
/* 197 */         if (hasAbility(p, Ability.SUICIDAL)) {
/* 198 */           if (hasCooldown(p)) {
/* 199 */             sendStillOnCooldown(p);
/*     */             return;
/*     */           } 
/* 202 */           setCooldown(p, this.plugin.config.SuicidalCooldown);
/* 203 */           sendUseAbility(p);
/* 204 */           for (Entity f : p.getNearbyEntities(5.0D, 5.0D, 5.0D)) {
/* 205 */             if (!(f instanceof Damageable))
/* 206 */               return;  ((Damageable)f).damage(1.0D, (Entity)p);
/*     */           } 
/* 208 */           for (int i = 0; i < 2; i++) {
/* 209 */             TNTPrimed tnt = (TNTPrimed)p.getWorld().spawn(p.getLocation().add(0.0D, 1.0D, 0.0D), TNTPrimed.class);
/* 210 */             tnt.setFuseTicks(1);
/* 211 */             tnt.setMetadata("tnts", (MetadataValue)new FixedMetadataValue((Plugin)this.plugin, Boolean.valueOf(true)));
/*     */           } 
/*     */         } 
/*     */         return;
/*     */       } 
/* 216 */       if (item.equals(Material.BOOK)) {
/* 217 */         if (hasAbility(p, Ability.PHANTOM)) {
/* 218 */           if (hasCooldown(p)) {
/* 219 */             sendStillOnCooldown(p);
/*     */             return;
/*     */           } 
/* 222 */           for (Entity f : p.getNearbyEntities(50.0D, 50.0D, 50.0D)) {
/* 223 */             if (!f.getType().equals(EntityType.PLAYER))
/* 224 */               continue;  ((Player)f).playSound(f.getLocation(), Sound.WITHER_SPAWN, 1.0F, 1.0F);
/* 225 */             ((Player)f).sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PhantomNotHacking.replace("%player%", p.getName()));
/*     */           } 
/* 227 */           p.playSound(p.getLocation(), Sound.WITHER_SPAWN, 1.0F, 1.0F);
/* 228 */           p.setAllowFlight(true);
/* 229 */           sendUseAbility(p);
/* 230 */           setCooldown(p, this.plugin.config.PhantomCooldown);
/* 231 */           (new BukkitRunnable() {
/* 232 */               int Seconds = AbilityListener.this.plugin.config.PhantomFlightLastsFor;
/*     */               public void run() {
/* 234 */                 if (!p.isOnline() || !AbilityListener.this.hasKit(p)) {
/* 235 */                   cancel();
/*     */                   return;
/*     */                 } 
/* 238 */                 if (this.Seconds == 0) {
/* 239 */                   p.setAllowFlight(false);
/* 240 */                   cancel();
/*     */                   return;
/*     */                 } 
/* 243 */                 p.sendMessage(String.valueOf(AbilityListener.this.kb) + AbilityListener.this.plugin.msgs.PhantomFlyTimeLeft.replace("%seconds%", String.valueOf(this.Seconds)));
/* 244 */                 this.Seconds--;
/*     */               }
/* 246 */             }).runTaskTimer((Plugin)this.plugin, 0L, 20L);
/*     */         } 
/*     */         return;
/*     */       } 
/* 250 */       if (item.equals(Material.WATCH)) {
/* 251 */         if (hasAbility(p, Ability.TIMELORD)) {
/* 252 */           if (hasCooldown(p)) {
/* 253 */             sendStillOnCooldown(p);
/*     */             return;
/*     */           } 
/* 256 */           p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1.0F, 1.0F);
/* 257 */           sendUseAbility(p);
/* 258 */           setCooldown(p, this.plugin.config.TimelordCooldown);
/* 259 */           for (Entity x : p.getNearbyEntities(this.plugin.config.TimelordFreezeRadius, this.plugin.config.TimelordFreezeRadius, this.plugin.config.TimelordFreezeRadius)) {
/* 260 */             if (!x.getType().equals(EntityType.PLAYER))
/* 261 */               continue;  Player o = (Player)x;
/* 262 */             if (!hasKit(o)) {
/* 263 */               p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.UseAbilityDeny);
/*     */               continue;
/*     */             } 
/* 266 */             o.getWorld().playEffect(o.getLocation(), Effect.STEP_SOUND, 152);
/* 267 */             o.getWorld().playEffect(o.getLocation().add(0.0D, 1.0D, 0.0D), Effect.STEP_SOUND, 152);
/* 268 */             o.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, this.plugin.config.TimelordFreezeTime, 10));
/* 269 */             o.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, this.plugin.config.TimelordFreezeTime, -4));
/* 270 */             o.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1.0F, 1.0F);
/*     */           } 
/*     */         } 
/*     */         return;
/*     */       } 
/* 275 */       if (item.equals(Material.BRICK)) {
/* 276 */         if (hasAbility(p, Ability.BURROWER)) {
/* 277 */           if (hasCooldown(p)) {
/* 278 */             sendStillOnCooldown(p);
/*     */             return;
/*     */           } 
/* 281 */           sendUseAbility(p);
/* 282 */           setCooldown(p, this.plugin.config.BurrowerCooldown);
/* 283 */           ArrayList<Location> locations = getRoomLocations(p.getLocation());
/* 284 */           boolean isEmpty = true;
/* 285 */           for (Location loc : locations) {
/* 286 */             if (loc.getBlock().getType() != Material.AIR) {
/* 287 */               isEmpty = false;
/*     */               break;
/*     */             } 
/*     */           } 
/* 291 */           if (isEmpty) {
/* 292 */             final ArrayList<BlockState> states = new ArrayList<BlockState>();
/* 293 */             for (Location loc : locations) {
/* 294 */               states.add(loc.getBlock().getState());
/* 295 */               loc.getBlock().setType(Material.BRICK);
/*     */             } 
/* 297 */             ((Location)locations.get(0)).getBlock().setType(Material.GLOWSTONE);
/* 298 */             this.toRollback.addAll(states);
/* 299 */             p.teleport(p.getLocation().add(0.0D, 10.0D, 0.0D));
/* 300 */             Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, new Runnable() {
/*     */                   public void run() {
/* 302 */                     for (BlockState state : states) {
/* 303 */                       AbilityListener.this.Rollback(state);
/*     */                     }
/* 305 */                     AbilityListener.this.toRollback.removeAll(states);
/*     */                   }
/* 307 */                 },  this.plugin.config.BurrowerRoomLastsFor);
/*     */           } else {
/* 309 */             p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.BurrowerNoSpace);
/*     */             return;
/*     */           } 
/*     */         } 
/*     */         return;
/*     */       } 
/* 315 */       if (item.equals(Material.SLIME_BALL)) {
/* 316 */         if (hasAbility(p, Ability.ZEN)) {
/* 317 */           if (hasCooldown(p)) {
/* 318 */             sendStillOnCooldown(p);
/*     */             return;
/*     */           } 
/* 321 */           setCooldown(p, this.plugin.config.ZenCooldown);
/* 322 */           sendUseAbility(p);
/* 323 */           boolean FoundPlayer = false;
/* 324 */           for (Entity f : p.getNearbyEntities(this.plugin.config.ZenMaxRange, this.plugin.config.ZenMaxRange, this.plugin.config.ZenMaxRange)) {
/* 325 */             if (f.getType() != EntityType.PLAYER)
/* 326 */               continue;  Player o = (Player)f;
/* 327 */             if (!hasKit(o) || 
/* 328 */               this.plugin.Fighting.containsKey(o.getName()))
/* 329 */               continue;  FoundPlayer = true;
/* 330 */             p.getWorld().playEffect(p.getLocation(), Effect.ENDER_SIGNAL, 1);
/* 331 */             p.teleport(o.getLocation());
/* 332 */             p.getWorld().playEffect(p.getLocation(), Effect.ENDER_SIGNAL, 1);
/*     */             break;
/*     */           } 
/* 335 */           if (!FoundPlayer) {
/* 336 */             p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.ZenNoPlayersFound);
/*     */           }
/*     */         } 
/*     */         return;
/*     */       } 
/* 341 */       if (item.equals(Material.SKULL_ITEM) && p.getItemInHand().getDurability() == 4) {
/* 342 */         if (hasAbility(p, Ability.HULK)) {
/* 343 */           if (hasCooldown(p)) {
/* 344 */             sendStillOnCooldown(p);
/*     */             return;
/*     */           } 
/* 347 */           sendUseAbility(p);
/* 348 */           setCooldown(p, this.plugin.config.HulkCooldown);
/* 349 */           p.getWorld().createExplosion(p.getLocation(), 0.0F, false);
/* 350 */           for (Location loc : this.plugin.listen.getSurroundingLocations(p.getLocation())) {
/* 351 */             p.getWorld().createExplosion(loc, 0.0F, false);
/*     */           }
/* 353 */           for (Entity f : p.getNearbyEntities(this.plugin.config.HulkDamageRadius, this.plugin.config.HulkDamageRadius, this.plugin.config.HulkDamageRadius)) {
/* 354 */             if (!(f instanceof Damageable))
/* 355 */               continue;  if (f.getType().equals(EntityType.PLAYER) && !hasKit((Player)f)) {
/* 356 */               p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.UseAbilityDeny);
/*     */               continue;
/*     */             } 
/* 359 */             ((Damageable)f).damage(this.plugin.config.HulkDamageDealt, (Entity)p);
/* 360 */             Vector v = f.getType().equals(EntityType.PLAYER) ? ((Player)f).getEyeLocation().getDirection() : f.getVelocity();
/* 361 */             v.multiply(-3);
/* 362 */             v.setY(1.0D);
/* 363 */             f.setVelocity(v);
/*     */           } 
/*     */         } 
/*     */         return;
/*     */       } 
/* 368 */       if (item.equals(Material.DIAMOND_BARDING)) {
/* 369 */         if (hasAbility(p, Ability.RIDER)) {
/* 370 */           e.setCancelled(true);
/* 371 */           if (hasCooldown(p)) {
/* 372 */             sendStillOnCooldown(p);
/*     */             return;
/*     */           } 
/* 375 */           sendUseAbility(p);
/* 376 */           setCooldown(p, this.plugin.config.RiderCooldown);
/* 377 */           final Horse horse = (Horse)p.getWorld().spawnEntity(p.getLocation(), EntityType.HORSE);
/* 378 */           horse.setAdult();
/* 379 */           horse.setCustomName(String.valueOf(p.getName()) + "'s Horse");
/* 380 */           horse.setOwner((AnimalTamer)p);
/* 381 */           horse.setMaxHealth(20.0D);
/* 382 */           horse.setHealth(20.0D);
/* 383 */           horse.setMetadata("toRemove", (MetadataValue)new FixedMetadataValue((Plugin)this.plugin, Boolean.valueOf(true)));
/* 384 */           horse.getInventory().setSaddle(new ItemStack(Material.SADDLE));
/* 385 */           horse.setPassenger((Entity)p);
/* 386 */           this.toRemove.add(horse);
/* 387 */           Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, new Runnable() {
/*     */                 public void run() {
/* 389 */                   AbilityListener.this.toRemove.remove(horse);
/* 390 */                   horse.remove();
/*     */                 }
/* 392 */               },  this.plugin.config.RiderHorseLastsFor);
/*     */         } 
/*     */         return;
/*     */       } 
/* 396 */       if (item.equals(Material.IRON_BLOCK)) {
/* 397 */         if (hasAbility(p, Ability.SUMMONER)) {
/* 398 */           if (hasCooldown(p)) {
/* 399 */             sendStillOnCooldown(p);
/*     */             return;
/*     */           } 
/* 402 */           sendUseAbility(p);
/* 403 */           setCooldown(p, this.plugin.config.SummonerCooldown);
/* 404 */           final IronGolem golem = (IronGolem)p.getWorld().spawnEntity(p.getLocation(), EntityType.IRON_GOLEM);
/* 405 */           golem.setCustomName(String.valueOf(p.getName()) + "'s Golem");
/* 406 */           golem.setPassenger((Entity)p);
/* 407 */           golem.setMetadata("toRemove", (MetadataValue)new FixedMetadataValue((Plugin)this.plugin, Boolean.valueOf(true)));
/* 408 */           this.toRemove.add(golem);
/* 409 */           Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, new Runnable() {
/*     */                 public void run() {
/* 411 */                   AbilityListener.this.toRemove.remove(golem);
/* 412 */                   golem.remove();
/*     */                 }
/* 414 */               },  this.plugin.config.SummonerGolemLastsFor);
/*     */         } 
/*     */         return;
/*     */       } 
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   @EventHandler
/*     */   public void AbilityEntityDamageByEntitySnowballEvents(EntityDamageByEntityEvent e) {
/* 425 */     if (e.isCancelled())
/* 426 */       return;  if (!e.getDamager().getType().equals(EntityType.SNOWBALL))
/* 427 */       return;  Snowball snowball = (Snowball)e.getDamager();
/* 428 */     if (!(snowball.getShooter() instanceof Player))
/* 429 */       return;  Player p = (Player)snowball.getShooter();
/* 430 */     Entity damaged = e.getEntity();
/* 431 */     if (!hasKit(p))
/* 432 */       return;  if (damaged.getType().equals(EntityType.PLAYER) && !hasKit((Player)damaged)) {
/* 433 */       p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.UseAbilityDeny);
/*     */       return;
/*     */     } 
/* 436 */     if (hasAbility(p, Ability.SWITCHER)) {
/* 437 */       sendUseAbility(p);
/* 438 */       Location location = p.getLocation();
/* 439 */       p.teleport(damaged.getLocation());
/* 440 */       damaged.teleport(location);
/*     */       return;
/*     */     } 
/* 443 */     if (snowball.hasMetadata("spiderman")) {
/* 444 */       Location loc = damaged.getLocation();
/* 445 */       final List<BlockState> blocks = new ArrayList<BlockState>();
/* 446 */       Block b = loc.getBlock();
/* 447 */       if (b.getType().equals(Material.WATER) || b.getType().equals(Material.STATIONARY_WATER) || b.getType().equals(Material.LAVA) || b.getType().equals(Material.STATIONARY_LAVA)) {
/* 448 */         loc.add(0.0D, 1.0D, 0.0D);
/* 449 */         b = loc.getBlock();
/*     */       } 
/* 451 */       for (Location x : this.plugin.listen.getSurroundingLocations(loc)) {
/* 452 */         if (x.getBlock().getType().equals(Material.WEB))
/* 453 */           continue;  blocks.add(x.getBlock().getState());
/*     */       } 
/* 455 */       if (b.getType() != Material.WEB) {
/* 456 */         blocks.add(b.getState());
/*     */       }
/* 458 */       for (BlockState oo : blocks) {
/* 459 */         this.toRollback.add(oo);
/* 460 */         oo.getBlock().setType(Material.WEB);
/*     */       } 
/* 462 */       Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, new Runnable() {
/*     */             public void run() {
/* 464 */               for (BlockState state : blocks) {
/* 465 */                 state.getWorld().createExplosion(state.getLocation(), 0.0F, false);
/* 466 */                 AbilityListener.this.Rollback(state);
/* 467 */                 AbilityListener.this.toRollback.remove(state);
/*     */               } 
/*     */             }
/* 470 */           }this.plugin.config.SpidermanWebsLastFor);
/*     */       return;
/*     */     } 
/* 473 */     if (snowball.hasMetadata("prison")) {
/* 474 */       final ArrayList<Block> blocks = getCageBlocks(damaged.getLocation().add(0.0D, 9.0D, 0.0D));
/* 475 */       boolean hasSpace = true;
/* 476 */       for (Block b : blocks) {
/* 477 */         if (b.getType() != Material.AIR) {
/* 478 */           p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PrisonerNoSpace);
/* 479 */           hasSpace = false;
/*     */           break;
/*     */         } 
/*     */       } 
/* 483 */       if (!hasSpace)
/* 484 */         return;  final ArrayList<BlockState> previousBlocks = new ArrayList<BlockState>();
/* 485 */       for (Block b : blocks) {
/* 486 */         previousBlocks.add(b.getState());
/*     */       }
/* 488 */       ((Block)blocks.get(0)).setType(Material.MOSSY_COBBLESTONE);
/* 489 */       for (int i = 1; i < 5; i++) {
/* 490 */         ((Block)blocks.get(i)).setType(Material.IRON_FENCE);
/*     */       }
/* 492 */       ((Block)blocks.get(5)).setType(Material.MOSSY_COBBLESTONE);
/* 493 */       ((Block)blocks.get(6)).setType(Material.LAVA);
/* 494 */       ((Damageable)damaged).damage(1.0D, (Entity)p);
/* 495 */       damaged.teleport(damaged.getLocation().add(0.0D, 9.0D, 0.0D));
/* 496 */       this.toRollback.addAll(previousBlocks);
/* 497 */       Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, new Runnable() {
/*     */             public void run() {
/* 499 */               for (BlockState state : previousBlocks) {
/* 500 */                 AbilityListener.this.Rollback(state);
/*     */               }
/* 502 */               AbilityListener.this.toRollback.removeAll(previousBlocks);
/*     */             }
/* 504 */           },  this.plugin.config.PrisonerPrisonLastsFor);
/*     */       return;
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   @EventHandler
/*     */   public void AbilityEntityDamageByEntityRandomChancesEvent(EntityDamageByEntityEvent e) {
/* 512 */     if (e.isCancelled())
/* 513 */       return;  if (!e.getDamager().getType().equals(EntityType.PLAYER) || !e.getEntity().getType().equals(EntityType.PLAYER))
/* 514 */       return;  Player damager = (Player)e.getDamager();
/* 515 */     if (!hasKit(damager))
/* 516 */       return;  Player p = (Player)e.getEntity();
/* 517 */     if (!hasKit(p))
/* 518 */       return;  if (hasAbility(damager, Ability.VIPER)) {
/* 519 */       int randomPercent = this.random.nextInt(100) + 1;
/* 520 */       if (randomPercent <= this.plugin.config.ViperPoisonChance) {
/* 521 */         sendUseAbility(damager);
/* 522 */         p.removePotionEffect(PotionEffectType.POISON);
/* 523 */         p.addPotionEffect(this.plugin.config.poisonEffect);
/*     */       } 
/*     */       return;
/*     */     } 
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void AbilityEntityDamageEvent(EntityDamageEvent e) {
/* 531 */     if (e.getEntity().getType() != EntityType.PLAYER)
/* 532 */       return;  Player p = (Player)e.getEntity();
/* 533 */     if (!hasKit(p))
/* 534 */       return;  if (e.getCause().equals(EntityDamageEvent.DamageCause.FALL) && 
/* 535 */       hasAbility(p, Ability.STOMPER)) {
/* 536 */       double damage = e.getDamage();
/* 537 */       if (damage > this.plugin.config.StomperMaxFallDamage) e.setDamage(this.plugin.config.StomperMaxFallDamage); 
/* 538 */       p.playSound(p.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
/* 539 */       for (Entity x : p.getNearbyEntities(this.plugin.config.StomperStompRadius, this.plugin.config.StomperStompRadius, this.plugin.config.StomperStompRadius)) {
/* 540 */         if (!(x instanceof Damageable))
/* 541 */           return;  if (x instanceof Player) {
/* 542 */           Player target = (Player)x;
/* 543 */           if (!hasKit(target)) {
/* 544 */             p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.UseAbilityDeny);
/*     */             continue;
/*     */           } 
/* 547 */           target.playSound(target.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
/* 548 */           if (!target.isSneaking()) {
/* 549 */             target.damage(damage, (Entity)p); continue;
/*     */           } 
/* 551 */           if (damage > this.plugin.config.StomperMaxDamageDealtWhenStompedWhileShifting) {
/* 552 */             target.damage(this.plugin.config.StomperMaxDamageDealtWhenStompedWhileShifting); continue;
/*     */           } 
/* 554 */           target.damage(damage, (Entity)p);
/*     */           
/*     */           continue;
/*     */         } 
/* 558 */         ((Damageable)x).damage(damage, (Entity)p);
/*     */       } 
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   @EventHandler
/*     */   public void AbilityShootArrowEvent(ProjectileLaunchEvent e) {
/* 567 */     if (e.getEntity().getType() != EntityType.ARROW)
/* 568 */       return;  Arrow arrow = (Arrow)e.getEntity();
/* 569 */     if (!(arrow.getShooter() instanceof Player))
/* 570 */       return;  Player p = (Player)arrow.getShooter();
/* 571 */     if (!hasKit(p))
/* 572 */       return;  if (hasAbility(p, Ability.CLIMBER)) {
/* 573 */       e.setCancelled(true);
/* 574 */       if (hasCooldown(p)) {
/* 575 */         sendStillOnCooldown(p);
/*     */         return;
/*     */       } 
/* 578 */       setCooldown(p, this.plugin.config.ClimberCooldown);
/* 579 */       final Chicken chicken = (Chicken)p.getWorld().spawnEntity(p.getLocation(), EntityType.CHICKEN);
/* 580 */       chicken.setVelocity(arrow.getVelocity().multiply(2));
/* 581 */       chicken.setPassenger((Entity)p);
/* 582 */       chicken.setMetadata("toRemove", (MetadataValue)new FixedMetadataValue((Plugin)this.plugin, Boolean.valueOf(true)));
/* 583 */       sendUseAbility(p);
/* 584 */       this.toRemove.add(chicken);
/* 585 */       Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, new Runnable() {
/*     */             public void run() {
/* 587 */               AbilityListener.this.toRemove.remove(chicken);
/* 588 */               chicken.remove();
/*     */             }
/* 590 */           },  this.plugin.config.ClimberTimeUntilChickenDisappear);
/*     */     } 
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void AbilityEntityExplode(EntityExplodeEvent e) {
/* 596 */     if (e.getEntity() == null)
/* 597 */       return;  if (e.getEntity().hasMetadata("tnts")) e.blockList().clear(); 
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void AbilityFishEvent(PlayerFishEvent e) {
/* 602 */     Player p = e.getPlayer();
/* 603 */     if (hasKit(p) && 
/* 604 */       e.getState().equals(PlayerFishEvent.State.CAUGHT_ENTITY) && 
/* 605 */       hasAbility(p, Ability.FISHERMAN)) {
/* 606 */       if (e.getCaught().getType().equals(EntityType.PLAYER) && !hasKit((Player)e.getCaught())) {
/* 607 */         p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.UseAbilityDeny);
/*     */         return;
/*     */       } 
/* 610 */       e.getCaught().teleport(p.getLocation());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   @EventHandler
/*     */   public void AbilityPlayerInteractEntityEvent(PlayerInteractEntityEvent e) {
/* 618 */     if (e.isCancelled())
/* 619 */       return;  if (!e.getRightClicked().getType().equals(EntityType.PLAYER))
/* 620 */       return;  Player p = e.getPlayer();
/* 621 */     if (!hasKit(p))
/* 622 */       return;  if (p.getItemInHand().getType() != Material.BLAZE_ROD)
/* 623 */       return;  if (hasAbility(p, Ability.MONK)) {
/* 624 */       if (hasCooldown(p)) {
/* 625 */         sendStillOnCooldown(p);
/*     */         return;
/*     */       } 
/* 628 */       Player clicked = (Player)e.getRightClicked();
/* 629 */       setCooldown(p, this.plugin.config.MonkCooldown);
/* 630 */       sendUseAbility(p);
/* 631 */       if (!hasKit(clicked)) {
/* 632 */         p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.UseAbilityDeny);
/*     */         return;
/*     */       } 
/* 635 */       int oldSlot = clicked.getInventory().getHeldItemSlot();
/* 636 */       int newSlot = this.random.nextInt(9);
/* 637 */       while (oldSlot == newSlot) {
/* 638 */         newSlot = this.random.nextInt(9);
/*     */       }
/* 640 */       ItemStack oldItem = clicked.getItemInHand();
/* 641 */       ItemStack newItem = clicked.getInventory().getItem(newSlot);
/* 642 */       clicked.getInventory().setItem(oldSlot, newItem);
/* 643 */       clicked.getInventory().setItem(newSlot, oldItem);
/* 644 */       clicked.updateInventory();
/*     */     } 
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void AbilityEntityDeathEvent(EntityDeathEvent e) {
/* 650 */     if (e.getEntity().hasMetadata("toRemove")) {
/* 651 */       e.setDroppedExp(0);
/* 652 */       e.getDrops().clear();
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/* 657 */   public void sendUseAbility(Player p) { p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerUseAbility); }
/*     */ 
/*     */ 
/*     */   
/* 661 */   public void sendStillOnCooldown(Player p) { p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.StillOnCooldown.replace("%time%", String.valueOf(getCooldown(p)))); }
/*     */ 
/*     */ 
/*     */   
/* 665 */   public boolean hasKit(Player p) { return (((PlayerData)this.plugin.playerData.get(p.getName())).getKit() != null); }
/*     */ 
/*     */ 
/*     */   
/* 669 */   public boolean hasCooldown(Player p) { return (((PlayerData)this.plugin.playerData.get(p.getName())).cooldown - System.currentTimeMillis() > 0L); }
/*     */ 
/*     */ 
/*     */   
/* 673 */   public void setCooldown(Player p, int Seconds) { ((PlayerData)this.plugin.playerData.get(p.getName())).cooldown = System.currentTimeMillis() + (1000 * Seconds); }
/*     */ 
/*     */ 
/*     */   
/* 677 */   public int getCooldown(Player p) { return (int)((((PlayerData)this.plugin.playerData.get(p.getName())).cooldown - System.currentTimeMillis()) / 1000L); }
/*     */ 
/*     */ 
/*     */   
/* 681 */   public boolean hasAbility(Player p, Ability ability) { return ((PlayerData)this.plugin.playerData.get(p.getName())).getKit().getAbilities().contains(ability); }
/*     */ 
/*     */   
/*     */   public ArrayList<Block> getCageBlocks(Location middle) {
/* 685 */     ArrayList<Block> cage = new ArrayList<Block>();
/*     */     
/* 687 */     cage.add(middle.clone().add(0.0D, -1.0D, 0.0D).getBlock());
/*     */     
/* 689 */     for (Location loc : this.plugin.listen.getSurroundingLocations(middle)) {
/* 690 */       cage.add(loc.getBlock());
/*     */     }
/*     */     
/* 693 */     cage.add(middle.clone().add(0.0D, 2.0D, 0.0D).getBlock());
/* 694 */     cage.add(middle.getBlock());
/* 695 */     cage.add(middle.add(0.0D, 1.0D, 0.0D).getBlock());
/* 696 */     return cage;
/*     */   }
/*     */   
/*     */   public ArrayList<Location> getPlatForm(Location location) {
/* 700 */     ArrayList<Location> platform = new ArrayList<Location>();
/* 701 */     platform.add(location.clone());
/* 702 */     platform.add(location.clone().add(-1.0D, 0.0D, 0.0D));
/* 703 */     platform.add(location.clone().add(0.0D, 0.0D, -1.0D));
/* 704 */     platform.add(location.clone().add(1.0D, 0.0D, 0.0D));
/* 705 */     platform.add(location.clone().add(0.0D, 0.0D, 1.0D));
/* 706 */     platform.add(location.clone().add(-1.0D, 0.0D, -1.0D));
/* 707 */     platform.add(location.clone().add(1.0D, 0.0D, -1.0D));
/* 708 */     platform.add(location.clone().add(1.0D, 0.0D, 1.0D));
/* 709 */     platform.add(location.clone().add(-1.0D, 0.0D, 1.0D));
/* 710 */     return platform;
/*     */   }
/*     */   
/*     */   public ArrayList<Location> getRoomLocations(Location location) {
/* 714 */     ArrayList<Location> room = new ArrayList<Location>();
/* 715 */     location.add(0.0D, 9.0D, 0.0D);
/* 716 */     room.addAll(getPlatForm(location));
/*     */     
/* 718 */     for (int i = 0; i < 3; i++) {
/* 719 */       location.add(0.0D, 1.0D, 0.0D);
/* 720 */       room.add(location.clone().add(0.0D, 0.0D, -2.0D));
/* 721 */       room.add(location.clone().add(0.0D, 0.0D, 2.0D));
/* 722 */       room.add(location.clone().add(2.0D, 0.0D, 0.0D));
/* 723 */       room.add(location.clone().add(-2.0D, 0.0D, 0.0D));
/*     */ 
/*     */       
/* 726 */       room.add(location.clone().add(-2.0D, 0.0D, 2.0D));
/* 727 */       room.add(location.clone().add(-2.0D, 0.0D, -2.0D));
/* 728 */       room.add(location.clone().add(2.0D, 0.0D, -2.0D));
/* 729 */       room.add(location.clone().add(2.0D, 0.0D, 2.0D));
/*     */       
/* 731 */       room.add(location.clone().add(1.0D, 0.0D, 2.0D));
/* 732 */       room.add(location.clone().add(-1.0D, 0.0D, 2.0D));
/* 733 */       room.add(location.clone().add(-2.0D, 0.0D, 1.0D));
/* 734 */       room.add(location.clone().add(-2.0D, 0.0D, -1.0D));
/* 735 */       room.add(location.clone().add(-1.0D, 0.0D, -2.0D));
/* 736 */       room.add(location.clone().add(1.0D, 0.0D, -2.0D));
/* 737 */       room.add(location.clone().add(2.0D, 0.0D, -1.0D));
/* 738 */       room.add(location.clone().add(2.0D, 0.0D, 1.0D));
/*     */     } 
/*     */     
/* 741 */     room.addAll(getPlatForm(location.add(0.0D, 1.0D, 0.0D)));
/*     */     
/* 743 */     return room;
/*     */   }
/*     */   
/*     */   public void Rollback(BlockState state) {
/* 747 */     if (state instanceof Sign) {
/* 748 */       Sign s = (Sign)state;
/* 749 */       Location loc = s.getLocation();
/* 750 */       loc.getWorld().getBlockAt(loc).setType(state.getType());
/* 751 */       Sign x = (Sign)loc.getWorld().getBlockAt(loc).getState();
/* 752 */       for (int i = 0; i < 4; i++) {
/* 753 */         x.setLine(i, s.getLines()[i]);
/*     */       }
/* 755 */       x.update(true);
/*     */     } else {
/* 757 */       state.update(true);
/*     */     } 
/*     */   }
/*     */ }


/* Location:              C:\Users\韩烨均\Documents\Tencent Files\133280410\FileRecv\KitBattle.jar!\me\wazup\kitbattle\AbilityListener.class
 * Java compiler version: 5 (49.0)
 * JD-Core Version:       1.1.2
 */